﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SqlAntlr
{
    public class RelationSchema
    {
        String relationName;
        HashSet<String> attributes;

        public RelationSchema(String relationName)
        {
            this.relationName = relationName.ToLower();
            this.attributes = new HashSet<String>();
        }

        public RelationSchema(String n, RelationSchema r)
        {
            relationName = n.ToLower();
            attributes = new HashSet<String>(r.attributes);
        }

        public RelationSchema(String relationName, String attrsDescr)
            : this(relationName)
        {
            //process attrsDescr here!!! :)
        }

        public void Add(String attr)
        {
            attributes.Add(attr.ToLower());
        }

        public void AddAttribute(String attribute)
        {
            attributes.Add(attribute);
        }

        public String getRelationName()
        {
            return relationName;
        }

        public bool contains(String attr)
        {
            return attributes.Contains(attr);
        }

        public ISet<String> getAll()
        {
            return attributes;
        }

        public String[] toArray()
        {
            return attributes.ToArray();
        }

        public List<String> getAttributes()
        {
            return new List<String>(attributes);
        }

        public int size() { return attributes.Count; }

        public override int GetHashCode()
        {
            return relationName.GetHashCode();
        }


        public bool equals(Object o)
        {
            if (this == o) return true;
            if (o is String)
            {
                return relationName.ToLower().Equals(((String)o).ToLower());
            }
            else if (o is RelationSchema)
            {
                return relationName.Equals(((RelationSchema)o).relationName);
            }
            return false;
        }
    }
}
